lotrfandomcom_pl-20200214-history
Moduł:Sprawdź
return { "Porównaj" = function(frame) local config = frame:getParent().args"" or "" local options = mw.text.split(config, "|") local templateName = mw.text.trim(options1) if #templateName 0 then local title = mw.title.getCurrentTitle() if title.namespace 10 then templateName = mw.ustring.match(title.text, "^(.-)/opis") or mw.ustring.match(title.text, "^(.-)/test") or mw.ustring.match(title.text, "^(.-)/brudnopis") or title.text end if #templateName 0 then mw.log("brak nazwy szablonu") return end end local templateTitle = mw.title.new(templateName, 10) if templateTitle.id 0 then mw.log("szablon '"..templateName.."' nie istnieje") return end local sandboxName = templateName.."/brudnopis" local sandboxTitle = mw.title.new(sandboxName, 10) if sandboxTitle.id 0 then mw.log("brudnopis '"..sandboxName.."' nie istnieje") return end local i = 2 local showparams = true local showinfo = true local vertical = false while i <= #options do local option = mw.text.trim(optionsi) if option "bez wikikodu" then showparams = false elseif option "bez opisu" then showinfo = false elseif option "pionowo" then vertical = true end i = i + 1 end local templateParams = {} local params = {} for k, v in pairs(frame:getParent().args) do if k ~= "" then templateParamsk = v table.insert(params, k) end end local result = {} table.insert(result, ' ') if showparams and (#params > 0) then local compare = function(a, b) -- return a < b if (type(a) "number") and (type(b) "number") then return a < b end if (type(a) "string") and (type(b) "string") then return a < b end if (type(a) "number") and (type(b) "string") then return true end return false end table.sort(params, compare) table.insert(result, " ") end local templateResult = frame:expandTemplate{ title=templateName, args=templateParams} local sandboxResult = frame:expandTemplate{ title=sandboxName, args=templateParams} if templateResult and string.match(templateResult, "^{|") then templateResult = "\n"..templateResult end if sandboxResult and string.match(sandboxResult, "^{|") then sandboxResult = "\n"..sandboxResult end if vertical and showinfo then table.insert(result, ' Szablon ') table.insert(result, templateResult) table.insert(result, ' Brudnopis szablonu ') table.insert(result, sandboxResult) table.insert(result, ' ') elseif vertical then table.insert(result, ' ') table.insert(result, templateResult) table.insert(result, ' ') table.insert(result, sandboxResult) table.insert(result, ' ') else if showinfo then table.insert(result, ' Szablon Brudnopis szablonu ') end table.insert(result, ' ') table.insert(result, templateResult) table.insert(result, ' ') table.insert(result, sandboxResult) table.insert(result, ' ') end table.insert(result, " ") return table.concat(result) end, "Parametry" = function(frame) local unknown = {} local invalid = {} local deprecated = {} local config = frame.args"" local class, category = string.match(frame.args"" or "", "^%s*(%S+)%s+(.-)%s*$") if not class then class = config end local function argName(arg) return type(arg) ~= "string" and tostring(arg) or ('"'..arg..'"') end local emptyArg = false for k, v in pairs(frame:getParent().args) do local kind = frame.argsk if k "" then emptyArg = v elseif not kind then table.insert(unknown, argName(k)) elseif kind "num" then local n = tonumber(v) if not n then table.insert(invalid, argName(k)) end elseif kind "num?" then local n = (#v 0) or tonumber(v) if not n then table.insert(invalid, argName(k)) end elseif kind "txt" then if #v 0 then table.insert(invalid, argName(k)) end elseif kind "old" then table.insert(deprecated, argName(k)) end end if (#unknown 0) and (#invalid 0) and (#deprecated 0) then return nil end local result = mw.html.create("span") if class then result:addClass(class) end if mw.title.getCurrentTitle().namespace 0 then result:css("display", "none") else result:css("color", "red") end if emptyArg then result:wikitext("|=", emptyArg, "| ") end if #invalid > 0 then result:wikitext("Nieprawidłowe pola: ", mw.text.listToText(invalid), ". ") end if #unknown > 0 then result:wikitext("Nieznane pola: ", mw.text.listToText(unknown), ". ") end if #deprecated > 0 then result:wikitext("Przestarzałe pola: ", mw.text.listToText(deprecated), ". ") end if category then result:wikitext(category) end return result end, "odn" = function(frame) local pf = frame:getParent() local i = 1 local problems = false local yeardetected = false while true do local arg = pf.argsi if not arg then problems = i 1 and "brak argumentów" or false break end if (i > 5) or yeardetected then problems = "za dużo argumentów pozycyjnych" break end if #arg 0 then problems = "pusty argument" break end if arg ~= mw.text.trim(arg) then problems = "nieoczekiwane odstępy na początku lub końcu argumentu" break end if string.match(arg, "^%d+%l?$") then yeardetected = true if i 1 then problems = "rok musi być ostatnim parametrem po nazwiskach autorów" break end elseif string.match(arg, "^s%-%.:%s*%d+") then problems = "prawdopodobnie nieprawidłowo podany numer strony" break elseif string.match(arg, "%s%s") then problems = "podwójne odstępy" break elseif mw.ustring.match(arg, "^%a+%d") then if not mw.ustring.match(arg, "^%u%d+$") then problems = "prawdopodobnie sklejone argumenty (brak pionowej kreski)" break end elseif mw.ustring.match(arg, "^%u%l+%u") then local justification = { "De" = true, "Del" = true, "Di" = true, "Le" = true, "Mac" = true, "Mc" = true, "Te" = true, -- TeSelle } if not justification"^%u%l+") then problems = "prawdopodobnie sklejone argumenty (brak pionowej kreski)" break end end i = i + 1 end if not problems then local odn = pf.args.odn if odn and ((#odn ~= 1) or (odn < "a") or (odn > "z")) then problems = "nieoczekiwany parametr odn" end end if not problems then local s = pf.args.s if s and string.match(s, "&a-z+;") then problems = "użyto encji HTML w numerze strony" end end if not problems then if pf.args.strona or pf.args.ss or pf.args.strony or pf.args.p or pf.args.page or pf.args.pp or pf.args.pages then problems = "przestarzały parametr z numerem strony" end end if not problems then return nil end local result = mw.html.create("span"):addClass("problemy-w-odn") if mw.title.getCurrentTitle().namespace 0 then result:css("display", "none") result:wikitext("Kategoria:Szablon odn do sprawdzenia") else result:css("color", "red") end result:wikitext("ODN: ", problems) return tostring(result) end, "Wikidane" = function(frame) local property = frame.args.cecha local field = frame.args.pole local value = frame.args1 if not property or not field then return end if not value then value = frame:getParent().argsfield if not value or (#value 0) then return end end local entity = mw.wikibase.getEntity() if not entity or not entity.claims or not entity.claimsproperty then return end for i, v in ipairs(entity.claimsproperty) do if v.mainsnak.snaktype "value" then if value v.mainsnak.datavalue.value then return end end end local template = frame:getParent():getTitle() local infobox = mw.ustring.match(template, "^Szablon:(.- infobox)$") return mw.ustring.format("Kategoria:%s – niezgodność w Wikidanych – %s – %s", infobox and "Infoboksy" or "Szablony", infobox or template, field) end, }